package com.jerry.mingxing.ui.store;

import android.content.Context;
import android.net.Uri;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.StoreHeadBean;


import java.util.List;

/**
 * Created by Administrator on 2016/8/29.
 */
public class StoreAdvertisementAdapter extends PagerAdapter {

    private List<StoreHeadBean.DataBean.ItemsBean> totallist;
    private Context context;
    private LayoutInflater inflater;


    public StoreAdvertisementAdapter(List<StoreHeadBean.DataBean.ItemsBean> totallist, Context context) {
        this.totallist = totallist;
        this.context = context;
        this.inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {


        return Integer.MAX_VALUE/2;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
     /*   Message message = handler.obtainMessage();
        message.what=0;
        message.arg1=position;
        handler.sendMessageAtTime(message,1000);*/


            View view = inflater.inflate(R.layout.storefragment_viewpager_item, container, false);
            SimpleDraweeView storefragment_viewpager_item_sdv = (SimpleDraweeView) view.findViewById(R.id.storefragment_viewpager_item_sdv);


            int index = position % totallist.size();
            storefragment_viewpager_item_sdv.setImageURI(Uri.parse(totallist.get(index).getComponent().getPicUrl()));
            container.addView(view);


        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


    public void reloadData(List list) {
        totallist.clear();
        totallist.addAll(list);
        notifyDataSetChanged();
    }
}
